﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Sitecore.Data.Items;
using System.Data;
using Telerik.Web.UI;
using Workflow.Alerts.DAL;
using System.Web.UI.HtmlControls;

namespace Workflow.Alerts.Sublayout
{
    public partial class AlertDetailPage : BaseControl, IDetailsView, ISummaryDetailsView
    {
        #region Fields
        Int32? sum;
        String buttonClass = string.Empty;
        #endregion

        #region Properties
        public String Path { get; set; }
        public String BtnSummaryText
        {
            set
            {
                btnSummary.Text = value;
                if (buttonClass == "")
                {
                    buttonClass = btnSummary.CssClass;
                }
                btnSummary.CssClass = buttonClass;
                btnSummary.CssClass += " " + value;
            }
        }
        #endregion

        #region Delegates
        public event OnSummaryDetailsViewLoad OnSummaryLoad;
        public event OnSummaryDetailsViewAddRemarks OnSummaryAddRemarks;
        public event OnDetailsViewLoad OnDetailsLoad;
        public event OnDetailsViewChangeStatus OnChangeStatus;
        public event OnChangeContractor OnSummaryChangeContractor;
        public event OnChangeActualArea OnSummaryChangeActualArea;
        public event OnChangeActualStartDate OnSummaryChangeActualStartDate;
        public event OnChangeActualEndDate OnSummaryChangeActualEndDate;
        public event OnUpdateRemarks OnSummaryUpdateRemarks;
        public event OnUpdateTrafficComments OnSummaryUpdateTrafficComments;
        public event OnChangeActivityType OnSummaryChangeActivityType;
        public event OnSaveTrafficComment OnSummarySaveTrafficComment;
        public event OnHasTrafficProblemsChanged OnSummaryHasTrafficProblemsChanged;
        public event OnDetailsGereedMelden OnGereedMelden;
        public event OnDetailsClearReviewStatus OnClearReviewStatus;
        public event OnDetailsMeldingTerugNaarFacturatie OnMeldingTerugNaarFacturatie;
        public event OnDetailsSaveStatusChanges OnSaveStatusChanges;
        public event OnDetailsCheckUitgesteldHerstel OnCheckUitgesteldHerstel;
        public event OnSummaryPriceUpdated OnPriceUpdated;
        #endregion

        #region IDetailsView Properties
        Int32 IDetailsView.AlertId
        {
            get { return Int32.Parse(Request.QueryString["alertId"]); }
        }

        String IDetailsView.Code
        {
            set { lblCode.Text = value; }
        }

        String IDetailsView.Location
        {
            set { lblLocation.Text = value; }
        }

        String IDetailsView.AlertType
        {
            set { lblAlertType.Text = value; }
        }

        String IDetailsView.UseMunicipContractor
        {
            set
            {
                if (String.IsNullOrEmpty(value))
                {
                    ContractorName.Visible = false;
                }
                else
                {
                    lblContractorName.Text = value;
                }
            }
        }

        String IDetailsView.ActivityType
        {
            set { lblActivityType.Text = value; }
        }

        String IDetailsView.Area
        {
            set { lblArea.Text = value; }
            get { return lblArea.Text; }
        }

        String IDetailsView.NetworkOperatorName
        {
            set
            {
                lblNetworkOperatorName.Text = value;
                lblNetworkOperatorNameSummary.Text = value;
            }
        }

        String IDetailsView.ContractorName
        {
            set
            {
                //if (String.IsNullOrEmpty(value))
                //{
                //    ContractorName.Visible = false;
                //}
                //else
                //{
                //    lblContractorName.Text = value;
                //}
            }

            get
            {
                return lblContractorName.Text;
            }
        }

        String IDetailsView.EstimateStartDate
        {
            set { lblEstimateStartDate.Text = value; }
            get { return lblEstimateStartDate.Text; }
        }

        String IDetailsView.CreationDate
        {
            set { lblCreationDate.Text = value; }
        }

        String IDetailsView.EstimateEndDate
        {
            set { lblEstimateEndDate.Text = value; }
            get { return lblEstimateEndDate.Text; }
        }

        Boolean IDetailsView.Traffic
        {
            set { isTraffic.Checked = value; }
        }

        #endregion

        #region ISummaryDetailsView Properties

        Int32 ISummaryDetailsView.AlertId
        {
            get { return (this as IDetailsView).AlertId; }
        }

        Int16? ISummaryDetailsView.ActualArea
        {
            set
            {
                if (!value.HasValue)
                {
                    ActualData.Visible = false;
                    dtActualData.Attributes.Add("class", string.Concat(dtActualData.Attributes["class"], " empty"));
                }
                else
                {
                    txtActualArea.Value = value;
                }
            }

            get
            {
                return (Nullable<Int16>)txtActualArea.Value;
            }
        }

        DateTime? ISummaryDetailsView.ActualStartDate
        {
            set
            {
                rdpStartDate.SelectedDate = value;
            }
            get
            {
                return rdpStartDate.SelectedDate;
            }
        }

        DateTime? ISummaryDetailsView.ActualEndDate
        {
            set
            {
                rdpEndDate.SelectedDate = value;
            }

            get
            {
                return rdpEndDate.SelectedDate;
            }
        }

        EstateDataSet.RemarksDataTable ISummaryDetailsView.Comments
        {
            set
            {
                rptComments.DataSource = value;
                rptComments.DataBind();
            }
        }

        String ISummaryDetailsView.Comment
        {
            get
            {
                return txtComments.Text;
            }
        }

        String ISummaryDetailsView.NetworkOperatorAddress
        {
            set { lblNetworkOperatorAddress.Text = value; }
        }

        String ISummaryDetailsView.NetworkOperatorEmail
        {
            set
            {
                hlNetworkOperatorEmail.Text = value;
                hlNetworkOperatorEmail.NavigateUrl = string.Format("mailto:{0}", value);
            }
        }

        String ISummaryDetailsView.NetworkOperatorContactPhone
        {
            set
            {
                lblNetworkOperatorTel.Text = value;

            }
        }

        String ISummaryDetailsView.NetworkOperatorContactPerson
        {
            set { lblNetworkOperatorPerson.Text = value; }
        }

        Dictionary<int,string> ISummaryDetailsView.ContractorNameList
        {
            set
            {
                ddlContractorName.DataSource = value.OrderBy(k => k.Key); 
                ddlContractorName.DataTextField = "value";
                ddlContractorName.DataValueField = "key";
                DataBind();

                

            }
        }

        Int32? ISummaryDetailsView.ContractorId
        {
            get
            {
                if (string.IsNullOrEmpty(ddlContractorName.SelectedValue) || ddlContractorName.SelectedValue == "0")
                    return null;
                return (Nullable<Int32>)Int32.Parse(ddlContractorName.SelectedValue);
            }

            set
            {
                if (value.HasValue)
                {
                    ddlContractorName.Items.FindByValue(value.ToString()).Selected = true;
                }
                else
                {
                    if (ddlContractorName.Items.FindByValue("0") != null)
                        ddlContractorName.Items.FindByValue("0").Selected = true;
                }
            }
        }

        String ISummaryDetailsView.ContractorPhone
        {
            set { lblContractorTel.Text = value; }
        }

        String ISummaryDetailsView.ContractorEmail
        {
            set
            {

                hlContractorEmail.Text = value;
                hlContractorEmail.NavigateUrl = string.Format("mailto:{0}", value);

            }
        }

        String ISummaryDetailsView.ContractorContactPerson
        {
            set { lblContractorPerson.Text = value; }
        }

        Dictionary<int, string> ISummaryDetailsView.ActivityTypes
        {
            set
            {
                ddlActivityType.DataSource = value;
                ddlActivityType.DataTextField = "value";
                ddlActivityType.DataValueField = "key";
                DataBind();
            }
        }

        Int32 ISummaryDetailsView.ActivityType
        {
            get
            {
                return Int32.Parse(ddlActivityType.SelectedValue);
            }
            set
            {
                ddlActivityType.Items.FindByValue(value.ToString()).Selected = true;
            }
        }

        Boolean ISummaryDetailsView.HasTrafficProblems
        {
            get
            {
                return chkTraffic.Checked;
            }

            set
            {
                chkTraffic.Checked = value;
            }
        }

        EstateDataSet.RemarksDataTable ISummaryDetailsView.TrafficComments
        {
            set
            {
                rptTrafficComments.DataSource = value;
                rptTrafficComments.DataBind();
            }
        }

        String ISummaryDetailsView.TrafficComment
        {
            get
            {
                return txtTrafficComments.Text;
            }
        }

        String ISummaryDetailsView.MaterialsSum
        {
            set
            {
                ltMaterialsSum.Text = value;
            }
        }

        Boolean ISummaryDetailsView.IsHerstel {
            set
            {
                btnAccept.Enabled = !value;
                string classAttribute = string.Empty;
                if (!String.IsNullOrEmpty(btnAccept.CssClass))
                    classAttribute = btnAccept.CssClass.ToString().TrimEnd();

                if (value)
                {
                    classAttribute = string.Concat(classAttribute, " disabled");
                }
                else
                {
                    classAttribute = classAttribute.Replace("disabled", "");                 
                }
                btnAccept.CssClass = classAttribute;
            }
        }


        #endregion

        #region Private Methods
        private void SetClassForApproveButton()
        {
            if (CurrentUser.Type == WorkflowEnums.UserType.Municipality)
            {
                var currentstatus = Session["execute_CurrentStatus"];
                if (currentstatus != null)
                {
                    HtmlGenericControl btnControl = null;
                    var status = (WorkflowEnums.Status)((int)currentstatus);
                    string strclass = string.Empty;
                    switch (status)
                    {
                        case WorkflowEnums.Status.Approved:
                        case WorkflowEnums.Status.Accepted:
                            strclass = "approved";
                            break;
                        case WorkflowEnums.Status.PartiallyApproved:
                        case WorkflowEnums.Status.AcceptedPartially:
                            strclass = "partiallyApproved";
                            break;
                        case WorkflowEnums.Status.Rejected:
                        case WorkflowEnums.Status.Declined:
                            strclass = "rejected";
                            break;
                    }
                    if (Sitecore.Context.Item.Parent.Name == WorkflowConstants.NewAlerts)
                    {
                        btnControl = btnAlertApprove;
                    }
                    else if (Sitecore.Context.Item.Parent.Name == WorkflowConstants.Executed)
                    {
                        btnControl = btnAlertExecute;
                    }
                    if (btnControl != null)
                    {
                        string classAttribute = btnControl.Attributes["class"].ToString().TrimEnd();
                        var classes = classAttribute.Split(new char[] { ' ' });
                        if (classes.Last() == "approved" ||
                            classes.Last() == "partiallyApproved" ||
                            classes.Last() == "rejected")
                        {
                            classAttribute = classAttribute.Replace(" approved", "");
                            classAttribute = classAttribute.Replace(" partiallyApproved", "");
                            classAttribute = classAttribute.Replace(" rejected", "");
                        }

                        classAttribute += string.Concat(" ", strclass);
                        btnControl.Attributes.Remove("class");
                        btnControl.Attributes.Add("class", classAttribute);
                    }
                }
            }
        }
        private void FormEditableControls()
        {
            Sitecore.Data.Fields.CheckboxField isEditable = (Sitecore.Data.Fields.CheckboxField)Sitecore.Context.Item.Fields["IsEditable"];
            bool editable = isEditable != null ? isEditable.Checked : false;

            txtActualArea.Enabled = editable;
            rdpEndDate.Enabled = editable;
            rdpStartDate.Enabled = editable;

            ddlActivityType.Enabled = CurrentUser.Type == WorkflowEnums.UserType.Municipality;

            if (CurrentUser.Type == WorkflowEnums.UserType.Municipality &&
                Sitecore.Context.Item.Parent.Name == WorkflowConstants.Executed)
            {
                if (OnCheckUitgesteldHerstel != null)
                {
                    bool isherstel =  OnCheckUitgesteldHerstel();
                    if(!isherstel){
                        btnAccept.Enabled = false;
                        string classAttribute = string.Empty;
                        if(!String.IsNullOrEmpty(btnAccept.CssClass))
                            classAttribute = btnAccept.CssClass.ToString().TrimEnd();
                        classAttribute = string.Concat(classAttribute, " disabled");
                        btnAccept.CssClass = classAttribute;
                    }
                }
            }
        }
        private void CheckButtonsVisibility()
        {
            var currentstatus = Session["execute_CurrentStatus"];

            if (CurrentUser.Type == WorkflowEnums.UserType.Municipality)
            {
                SetClassForApproveButton();

                if (lblActivityType.Text == WorkflowEnums.ActivityTypeList[8] &&
                    Sitecore.Context.Item.Parent.Name == WorkflowConstants.InProgress)
                {
                    DivGereedMelden.Visible = true;
                    ReviewButtons.Visible = false;
                }
                if (Sitecore.Context.Item.Parent.Name == WorkflowConstants.Logged)
                {
                    DivMeldingTerugNaarFacturatie.Visible = true;
                }

                if (Sitecore.Context.Item.Parent.Name == WorkflowConstants.NewAlerts)
                {
                    var status = WorkflowEnums.Status.Sent;
                    if (currentstatus != null)
                    {
                        status = (WorkflowEnums.Status)((int)currentstatus);
                    }
                    if (status != WorkflowEnums.Status.Sent)
                    {
                        DivOpslaanVerzenden.Visible = true;
                    }
                    else
                    {
                        DivOpslaanVerzenden.Visible = false;
                    }
                }
                if (Sitecore.Context.Item.Parent.Name == WorkflowConstants.Executed)
                {
                    var status = WorkflowEnums.Status.Executed4Municipality;
                    if (currentstatus != null)
                    {
                        status = (WorkflowEnums.Status)((int)currentstatus);
                    }
                    if (status != WorkflowEnums.Status.Executed4Municipality)
                    {
                        DivOpslaanVerzenden.Visible = true;
                    }
                    else
                    {
                        DivOpslaanVerzenden.Visible = false;
                    }
                }
            }
            else
            {
                if (currentstatus != null)
                {
                    if (((Int32)currentstatus == (Int32)WorkflowEnums.Status.Executed4Contractor ||
                        (Int32)currentstatus == (Int32)WorkflowEnums.Status.Executed4Municipality) &&
                        Sitecore.Context.Item.Parent.Name == WorkflowConstants.InProgress)
                    {
                        InProgressButtons.Visible = false;
                    }
                }
            }
        }
        #endregion

        #region Events
        protected void Page_Init(object sender, EventArgs e)
        {
            if (Request.QueryString["sum"] != null)
            {
                mgList.Alert = Request.QueryString["alertId"];
                mgList.ShowHerstelCheckbox = true;
                mgList.SaveChangesInDB = true;
                mgList.PriceUpdated += new Workflow.Alerts.Sublayouts.MaterialsGrid.MaterialsUpdatePrice(mgList_PriceUpdated);
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            int _sum;
            if (Request.QueryString["sum"] != null && Int32.TryParse(Request.QueryString["sum"], out _sum))
                sum = _sum;

            #region Register presenters
            PresentationManager.RegisterView(typeof(DetailsViewPresenter), this, new WebSessionProvider());
            if (sum.HasValue)
            {
                PresentationManager.RegisterView(typeof(SummaryDetailsViewPresenter), this, new WebSessionProvider());
                ScriptManager.GetCurrent(this.Page).RegisterAsyncPostBackControl(mgList);
            }
            #endregion

            #region Set visibility of controls based on sitecore values

            Sitecore.Data.Fields.MultilistField selectedFields = (Sitecore.Data.Fields.MultilistField)Sitecore.Context.Item.Fields["DetailsVisibleFields"];
            if (selectedFields != null)
            {
                var visibleFields = selectedFields.GetItems();
                foreach (Item item in visibleFields)
                {
                    string ctrlName = item.Name.Replace(" ", "");
                    var ctrl = dtlsTable.FindControlRecursive(ctrlName);
                    if (ctrl != null)
                    {
                        ctrl.Visible = true;
                    }
                }
            }
            #endregion

            #region Set visibility for buttons
            Sitecore.Data.Fields.MultilistField buttons = (Sitecore.Data.Fields.MultilistField)Sitecore.Context.Item.Fields["DetailsActionButtons"];
            if (buttons != null)
            {
                var visibleButtons = buttons.GetItems();
                foreach (Item item in visibleButtons)
                {
                    string ctrlName = item.Name.Replace(" ", "");
                    var ctrl = dtlsTable.FindControlRecursive(ctrlName);
                    if (ctrl != null)
                    {
                        ctrl.Visible = true;
                    }
                }
            }
            #endregion

            #region Load details data
            if (OnDetailsLoad != null)
            {
                OnDetailsLoad();
            }
            #endregion

            #region Perform logic for summary screen
            if (sum.HasValue)
            {
                //check visibility of controls

                Sitecore.Data.Fields.MultilistField visibleSections = (Sitecore.Data.Fields.MultilistField)Sitecore.Context.Item.Fields["SummaryVisibleSections"];
                if (visibleSections != null)
                {
                    var sections = visibleSections.GetItems();
                    foreach (Item item in sections)
                    {
                        string ctrlName = item.Name.Replace(" ", "");
                        var ctrl = summary.FindControlRecursive(ctrlName);
                        if (ctrl != null)
                        {
                            ctrl.Visible = true;
                        }
                    }
                }

                Sitecore.Data.Fields.MultilistField visibleSummaryFields = (Sitecore.Data.Fields.MultilistField)Sitecore.Context.Item.Fields["SummaryVisibleFields"];
                if (visibleSummaryFields != null)
                {
                    var summaryFields = visibleSummaryFields.GetItems();
                    foreach (Item item in summaryFields)
                    {
                        string ctrlName = item.Name.Replace(" ", "");
                        var ctrl = summary.FindControlRecursive(ctrlName);
                        if (ctrl != null)
                        {
                            ctrl.Visible = true;
                        }
                    }
                }
                if (!IsPostBack)
                {
                    if (OnSummaryLoad != null)
                    {
                        OnSummaryLoad();
                    }
                }

                BtnSummaryText = "Terug";
            }
            else
            {
                BtnSummaryText = "Details";
                summary.Visible = false;
            }
            #endregion

            #region Actions based on user type
            if (CurrentUser.Type == WorkflowEnums.UserType.NetworkOperator)
            {
                MunicipalityName.Value = "/NetworkOperator/";
            }
            else
            {
                MunicipalityName.Value = string.Format("/{0}/", CurrentUser.Name);
            }
            #endregion

            CheckButtonsVisibility();

            FormEditableControls();
        }

        void mgList_PriceUpdated(object sender, EventArgs e)
        {
            if (OnPriceUpdated != null)
            {
                OnPriceUpdated();
            }
        }
        protected void btnSummary_Click(object sender, EventArgs e)
        {
            Item detailsPageItem = Sitecore.Context.Item.Axes.SelectSingleItem("../*[@@templatename='SummaryPage']");
            string detailsPath = Sitecore.Links.LinkManager.GetItemUrl(detailsPageItem);

            if (sum.HasValue)
            {
                Response.Redirect(string.Format("{0}?alertId={1}", detailsPath, (this as IDetailsView).AlertId));
            }
            else
            {

                Response.Redirect(string.Format("{0}?alertId={1}&sum=1", detailsPath, (this as IDetailsView).AlertId));
            }
        }
        protected void btnClick_Command(object sender, CommandEventArgs e)
        {
            switch (e.CommandName)
            {
                case "Accept":
                    if (OnChangeStatus != null)
                    {
                        OnChangeStatus((this as IDetailsView).AlertId, WorkflowEnums.Status.Accepted, (WorkflowEnums.Status)Session["execute_CurrentStatus"], false);
                        Session["execute_CurrentStatus"] = (Int32)WorkflowEnums.Status.Accepted;
                        SetClassForApproveButton();
                    }
                    break;
                case "Approve":
                    if (OnChangeStatus != null)
                    {
                        OnChangeStatus((this as IDetailsView).AlertId, WorkflowEnums.Status.Approved, WorkflowEnums.Status.Sent, false);
                        Session["execute_CurrentStatus"] = (Int32)WorkflowEnums.Status.Approved;
                        SetClassForApproveButton();
                    }
                    break;
                case "AcceptPartially":
                    break;
                case "PartApprove":
                    break;
                case "Reject":
                    break;
                case "ClearReview":
                    {
                        if (OnClearReviewStatus != null)
                        {
                            OnClearReviewStatus();
                            Session["execute_CurrentStatus"] = (Int32)WorkflowEnums.Status.Sent;
                            SetClassForApproveButton();
                        }
                    }
                    break;
                case "MeldingTerugNaarFacturatie":
                    {
                        if (OnMeldingTerugNaarFacturatie != null)
                        {
                            OnMeldingTerugNaarFacturatie();
                            Session[WorkflowConstants.OpenList] = "true";
                            this.Page.ClientScript.RegisterStartupScript(typeof(Page), "RefreshParent", "<script language='javascript'>RefreshParent()</script>");
                        }
                    }
                    break;

                case "OpslaanVerzenden":
                    {
                        if (OnSaveStatusChanges != null)
                        {
                            OnSaveStatusChanges();
                            Session[WorkflowConstants.OpenList] = "true";
                            this.Page.ClientScript.RegisterStartupScript(typeof(Page), "RefreshParent", "<script language='javascript'>RefreshParent()</script>");
                        }

                    }
                    break;
            }

            CheckButtonsVisibility();
        }
        protected void btnSaveRemark_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(txtComments.Text) && OnSummaryAddRemarks != null)
            {
                OnSummaryAddRemarks();
                txtComments.Text = string.Empty;
            }
        }
        protected void ddlContractorName_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (OnSummaryChangeContractor != null)
                OnSummaryChangeContractor();
        }
        protected void txtActualArea_ValueChanged(object sender, EventArgs e)
        {
            if (OnSummaryChangeActualArea != null)
                OnSummaryChangeActualArea();
        }
        protected void ddlActivityType_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (OnSummaryChangeActivityType != null)
                OnSummaryChangeActivityType();
        }
        protected void rdpStartDate_SelectedDateChanged(object sender, Telerik.Web.UI.Calendar.SelectedDateChangedEventArgs e)
        {
            if (OnSummaryChangeActualStartDate != null)
                OnSummaryChangeActualStartDate();
        }
        protected void rdpEndDate_SelectedDateChanged(object sender, Telerik.Web.UI.Calendar.SelectedDateChangedEventArgs e)
        {
            if (OnSummaryChangeActualEndDate != null)
                OnSummaryChangeActualEndDate();
        }
        protected void rptComments_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if ((e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) &&
                e.Item.DataItem != null)
            {
                var item = (EstateDataSet.RemarksRow)((DataRowView)e.Item.DataItem).Row;
                if (item.userid == CurrentUser.Id)
                {
                    Button btnEdit = (Button)e.Item.FindControl("btnEdit");
                    if (btnEdit != null)
                    {
                        btnEdit.Visible = true;
                        var txt = e.Item.FindControl("txtCommentBox");
                        btnEdit.Attributes.Add("onclick", string.Format("javascript:Show('{0}');return false;", txt.ClientID));
                    }
                }
            }
        }
        protected void rptComments_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "UpdateRemark")
            {
                var txtCtrl = (TextBox)e.Item.FindControl("txtComment");
                var lblCtrl = (Label)e.Item.FindControl("lblId");
                if (txtCtrl != null && lblCtrl != null && OnSummaryUpdateRemarks != null)
                {
                    OnSummaryUpdateRemarks(txtCtrl.Text, Int32.Parse(lblCtrl.Text));
                }
            }
        }
        protected void rptTrafficComments_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if ((e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) &&
                e.Item.DataItem != null)
            {
                var item = (EstateDataSet.RemarksRow)((DataRowView)e.Item.DataItem).Row;
                if (item.userid == CurrentUser.Id)
                {
                    Button btnEdit = (Button)e.Item.FindControl("btnEdit");
                    if (btnEdit != null)
                    {
                        btnEdit.Visible = true;
                        var txt = e.Item.FindControl("txtTrafficCommentBox");
                        btnEdit.Attributes.Add("onclick", string.Format("javascript:Show('{0}');return false;", txt.ClientID));
                    }
                }
            }
        }
        protected void rptTrafficComments_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "UpdateTrafficComments")
            {
                var txtCtrl = (TextBox)e.Item.FindControl("txtTrafficComment");
                var lblCtrl = (Label)e.Item.FindControl("lblId");
                if (txtCtrl != null && lblCtrl != null && OnSummaryUpdateRemarks != null)
                {
                    OnSummaryUpdateTrafficComments(txtCtrl.Text, Int32.Parse(lblCtrl.Text));
                }
            }
        }
        protected void btnSaveTrafficComment_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(txtTrafficComments.Text) && OnSummarySaveTrafficComment != null)
            {
                OnSummarySaveTrafficComment();
                txtTrafficComments.Text = string.Empty;
            }
        }
        protected void chkTraffic_CheckedChanged(object sender, EventArgs e)
        {
            if (OnSummaryHasTrafficProblemsChanged != null)
                OnSummaryHasTrafficProblemsChanged();
            isTraffic.Checked = chkTraffic.Checked;
        }
        protected void btnGereedMelden_OnClick(object sender, EventArgs e)
        {
            if (OnGereedMelden != null)
                OnGereedMelden();

            Session[WorkflowConstants.OpenList] = "true";
            this.Page.ClientScript.RegisterStartupScript(typeof(Page), "RefreshParent", "<script language='javascript'>RefreshParent()</script>");
        }

        #endregion


    }
}